﻿using Newtonsoft.Json;

namespace TimerTask.Common.Utils
{
    public class AppConfig
    {
        public static AppConfig Instance { internal set; get; }
        private static bool HasInited;

        public static void Init(string configJson)
        {
            if (HasInited)
            {
                return;
            }
            HasInited = true;
            Instance = JsonConvert.DeserializeObject<AppConfig>(configJson);
        }

        public string Name { get; set; }
        public string DbConnStr { set; get; }

        public string Ver { get; set; }

        public string Salt { get; set; }
        public int PageSize { set; get; }

        public int NotifyMethod { get; set; }

        public int NotifyInterval { set; get; }
        public EmailCfg EmailNotify { get; set; }
        public SmsCfg SmsNotify { get; set; }
    }

    public class EmailCfg
    {
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Smtp { get; set; }
        public string LocalDomain { get; set; }

        public string GetPwd()
        {
            return Base64Util.DeBase64(Password).Substring(3);
        }
    }
    public class SmsCfg
    {
        public string UserName { get; set; }
        public string ReqUrl { get; set; }
        public string Pwd { get; set; }
    }
}
